﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 库存超期产品处理项目查询工具
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            rbtnCx_CheckedChanged(this, new EventArgs());
        }

        private void rbtnCx_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnCx.Checked)
            {
                rbtnXq.Checked = false;
                rbtnBy.Checked = false;
                rbtnCy.Checked = false;

                //合同要求锡铅引出端或可焊性不合格
                gbXqh.Enabled = true;
                //是否片式产品
                gbIsChip.Enabled = true;
                //A卡号
                gbACardNo.Enabled = true;
                //J及以上等级
                gbClass.Enabled = true;
                //是否导电胶方式安装
                gbDdj.Enabled = false ;
                //B卡号
                gbBCardNo.Enabled = true;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnXq_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnXq.Checked)
            {
                rbtnCx.Checked = false;
                rbtnBy.Checked = false;
                rbtnCy.Checked = false;

                //合同要求锡铅引出端或可焊性不合格
                gbXqh.Enabled = true;
                //是否片式产品
                gbIsChip.Enabled = true;
                //A卡号
                gbACardNo.Enabled = true;
                //J及以上等级
                gbClass.Enabled = true;
                //是否导电胶方式安装
                gbDdj.Enabled = false ;
                //B卡号
                gbBCardNo.Enabled = true;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnBy_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnBy.Checked)
            {
                rbtnCx.Checked = false;
                rbtnXq.Checked = false;
                rbtnCy.Checked = false;

                //合同要求锡铅引出端或可焊性不合格
                gbXqh.Enabled = false;
                //是否片式产品
                gbIsChip.Enabled = false;
                //A卡号
                gbACardNo.Enabled = true;
                //J及以上等级
                gbClass.Enabled = true;
                //是否导电胶方式安装
                gbDdj.Enabled = true;
                //B卡号
                gbBCardNo.Enabled = true;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnCy_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnCy.Checked)
            {
                rbtnCx.Checked = false;
                rbtnXq.Checked = false;
                rbtnBy.Checked = false;

                //合同要求锡铅引出端或可焊性不合格
                gbXqh.Enabled = false;
                //是否片式产品
                gbIsChip.Enabled = false;
                //A卡号
                gbACardNo.Enabled = true;
                //J及以上等级
                gbClass.Enabled = true;
                //是否导电胶方式安装
                gbDdj.Enabled = false ;
                //B卡号
                gbBCardNo.Enabled = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnXqh_Yes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnXqh_Yes.Checked)
            {
                rbtnXqh_No.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnXqh_No_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnXqh_No.Checked)
            {
                rbtnXqh_Yes.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnIsChip_Yes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnIsChip_Yes.Checked)
            {
                rbtnIsChip_No.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnIsChip_No_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnIsChip_No.Checked)
            {
                rbtnIsChip_Yes.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnClass_Yes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnClass_Yes.Checked)
            {
                rbtnClass_No.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnClass_No_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnClass_No.Checked)
            {
                rbtnClass_Yes.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnDdj_Yes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnDdj_Yes.Checked)
            {
                rbtnDdj_No.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void rbtnDdj_No_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnDdj_No.Checked)
            {
                rbtnDdj_Yes.Checked = false;

                //刷新查询结果
                RefreshResult();
            }
        }

        private void txtACardNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                txtACardNo.Text = txtACardNo.Text.Trim().ToUpper ();

                //刷新查询结果
                RefreshResult();
            }
        }

        private void txtACardNo_Leave(object sender, EventArgs e)
        {
            txtACardNo.Text = txtACardNo.Text.Trim().ToUpper();

            //刷新查询结果
            RefreshResult();
        }

        private void txtBCardNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                txtBCardNo.Text = txtBCardNo.Text.Trim().ToUpper ();

                //刷新查询结果
                RefreshResult();
            }
        }

        private void txtBCardNo_Leave(object sender, EventArgs e)
        {
            txtBCardNo.Text = txtBCardNo.Text.Trim().ToUpper ();

            //刷新查询结果
            RefreshResult();
        }

        /// <summary>
        /// 刷新查询结果
        /// </summary>
        public void RefreshResult()
        {
            result r = new result();
            lstResult.Items.Clear();

            //纯锡引出端与锡铅引出端，项目一致
            if (rbtnCx.Checked || rbtnXq.Checked)
            {
                //锡铅化处理
                if (rbtnXqh_Yes.Checked)
                {
                    r.bXqh = true;
                }
                else
                {
                    r.bXqh = false;
                }

                //去氧化处理
                r.bQyh = false;

                //可焊性
                r.bKhx = true;

                //附着力
                r.bFzl = true;

                //安装牢固性
                r.bAzlgx = false;

                //抗剪切强度
                r.bKjqqd = false;

                //端面结合强度
                if (rbtnIsChip_Yes.Checked)
                {
                    if (rbtnClass_Yes.Checked)
                    {
                        if (txtACardNo.Text.Length >= 4)
                        {
                            if (!txtACardNo.Text.StartsWith ("S"))
                            {
                                if (txtACardNo.Text.Substring(0, 4).CompareTo("1A05") == -1)
                                {
                                    r.bDmjhqd = true;
                                }
                                else
                                {
                                    r.bDmjhqd = false;
                                }
                            }
                            else 
                            {
                                r.bDmjhqd = true;
                            }
                        }
                        else
                        {
                            lstResult.Items.Add("条件不完整，无法查询准确结果。请检查查询条件（A卡号不符合格式要求）");
                            txtACardNo.Focus();
                            return;
                        }
                    }
                    else
                    {
                        r.bDmjhqd = false;
                    }
                }
                else
                {
                    r.bDmjhqd = false;
                }

                //耐焊接热
                r.bNhjr = r.bDmjhqd;

                //击穿电压
                if (rbtnClass_Yes.Checked)
                {
                    if (txtACardNo.Text.Length >= 4)
                    {
                        if (!txtACardNo.Text.StartsWith("S"))
                        {
                            if (txtACardNo.Text.Substring(0, 4).CompareTo("1B11") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo .Text .Length -4, 4)) < 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                        else 
                        {
                            if (txtACardNo.Text.Substring(0, 3).CompareTo("S05") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo .Text .Length -4, 4)) >= 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                    }
                    else
                    {
                        lstResult.Items.Add("条件不完整，无法查询准确结果。请检查查询条件（A卡号不符合格式要求）");
                        txtACardNo.Focus();
                        return;
                    }
                }
                else
                {
                    r.bJcdy = false;
                }

                //无损检测
                if (rbtnIsChip_Yes.Checked)
                {
                    if (rbtnClass_Yes.Checked)
                    {
                        if (txtBCardNo.Text.Length >=4&&txtBCardNo.Text.Substring(0, 4).CompareTo("1001") == -1)
                        {
                            r.bWsjc = true;
                        }
                        else
                        {
                            r.bWsjc = false;
                        }
                    }
                    else
                    {
                        r.bWsjc = false;
                    }
                }
                else
                {
                    r.bWsjc = false;
                }

                //电性能
                r.bDxn = true;
            }

            //钯银引出端
            if (rbtnBy.Checked)
            {
                //锡铅化处理
                r.bXqh = false;

                //去氧化处理
                r.bQyh = true;

                //可焊性
                r.bKhx = true;

                //附着力
                r.bFzl = false;

                //安装牢固性
                r.bAzlgx = true;

                //抗剪切强度
                r.bKjqqd = true;

                //端面结合强度
                if (rbtnDdj_Yes.Checked)
                {
                    if (rbtnClass_Yes.Checked)
                    {
                        if (txtACardNo.Text.Length >= 4)
                        {
                            if (txtACardNo.Text.Substring(0, 4).CompareTo("1A05") == -1)
                            {
                                r.bDmjhqd = true;
                            }
                            else
                            {
                                r.bDmjhqd = false;
                            }
                        }
                        else if (txtACardNo.Text.Length == 9 && txtACardNo.Text.ToUpper().StartsWith("S"))
                        {
                            r.bDmjhqd = true;
                        }
                        else
                        {
                            lstResult.Items.Add("条件不完整，无法查询准确结果。请检查查询条件（A卡号不符合格式要求）");
                            txtACardNo.Focus();
                            return;
                        }
                    }
                    else
                    {
                        r.bDmjhqd = false;
                    }
                }
                else
                {
                    r.bDmjhqd = false;
                }

                //耐焊接热
                r.bNhjr = r.bDmjhqd;

                //击穿电压
                if (rbtnClass_Yes.Checked)
                {
                    if (txtACardNo.Text.Length >= 4)
                    {
                        if (!txtACardNo.Text.StartsWith("S"))
                        {
                            if (txtACardNo.Text.Substring(0, 4).CompareTo("1B11") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo.Text.Length - 4, 4)) < 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                        else
                        {
                            if (txtACardNo.Text.Substring(0, 3).CompareTo("S05") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo.Text.Length - 4, 4)) >= 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                    }
                    else
                    {
                        lstResult.Items.Add("条件不完整，无法查询准确结果。请检查查询条件（A卡号不符合格式要求）");
                        txtACardNo.Focus();
                        return;
                    }
                }
                else
                {
                    r.bJcdy = false;
                }

                //无损检测
                if (rbtnClass_Yes.Checked)
                {
                    if (txtBCardNo.Text.Length >=4&&txtBCardNo.Text.Substring(0, 4).CompareTo("1001") == -1)
                    {
                        r.bWsjc = true;
                    }
                    else
                    {
                        r.bWsjc = false;
                    }
                }
                else
                {
                    r.bWsjc = false;
                }

                //电性能
                r.bDxn = true;
            }

            //纯银引出端
            if (rbtnCy.Checked)
            {
                //锡铅化处理
                r.bXqh = false;

                //去氧化处理
                r.bQyh = false;

                //可焊性
                r.bKhx = true;

                //附着力
                r.bFzl = false;

                //安装牢固性
                r.bAzlgx = false;

                //抗剪切强度
                r.bKjqqd = false;

                //端面结合强度
                r.bDmjhqd = false;

                //耐焊接热
                r.bNhjr = r.bDmjhqd;

                //击穿电压
                if (rbtnClass_Yes.Checked)
                {
                    if (txtACardNo.Text.Length >= 4)
                    {
                        if (!txtACardNo.Text.StartsWith("S"))
                        {
                            if (txtACardNo.Text.Substring(0, 4).CompareTo("1B11") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo.Text.Length - 4, 4)) < 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                        else
                        {
                            if (txtACardNo.Text.Substring(0, 3).CompareTo("S05") == -1 && int.Parse(txtACardNo.Text.Substring(txtACardNo.Text.Length - 4, 4)) >= 1500)
                            {
                                r.bJcdy = true;
                            }
                            else
                            {
                                r.bJcdy = false;
                            }
                        }
                    }
                    else
                    {
                        lstResult.Items.Add("条件不完整，无法查询准确结果。请检查查询条件（A卡号不符合格式要求）");
                        txtACardNo.Focus();
                        return;
                    }
                }
                else
                {
                    r.bJcdy = false;
                }

                //无损检测
                r.bWsjc = false;

                //电性能
                r.bDxn = true;
            }

            //刷新查询结果
            if (r.bXqh)
            {
                lstResult.Items.Add("锡铅化处理");
            }
            if (r.bQyh)
            {
                lstResult.Items.Add("去氧化处理");
            }
            if (r.bKhx)
            {
                lstResult.Items.Add("可焊性");
            }
            if (r.bFzl)
            {
                lstResult.Items.Add("附着力");
            }
            if (r.bAzlgx)
            {
                lstResult.Items.Add("安装牢固性");
            }
            if (r.bKjqqd)
            {
                lstResult.Items.Add("抗剪切强度");
            }
            if (r.bDmjhqd )
            {
                lstResult.Items.Add("端面结合强度");
            }
            if (r.bNhjr )
            {
                lstResult.Items.Add("耐焊接热");
            }
            if (r.bJcdy )
            {
                lstResult.Items.Add("击穿电压");
            }
            if (r.bWsjc )
            {
                lstResult.Items.Add("无损检测");
            }
            if (r.bDxn )
            {
                lstResult.Items.Add("电性能");
            }
        }

        
    }

    public class result
    {
        /// <summary>
        /// 锡铅化处理，纯锡及锡铅满足条件时要做
        /// </summary>
        public bool bXqh;

        /// <summary>
        /// 去氧化处理，仅钯银要做
        /// </summary>
        public bool bQyh;

        /// <summary>
        /// 可焊性，必做
        /// </summary>
        public bool bKhx = true;

        /// <summary>
        /// 附着力，纯锡及锡铅要做
        /// </summary>
        public bool bFzl;

        /// <summary>
        /// 安装牢固性，仅钯银要做
        /// </summary>
        public bool bAzlgx;

        /// <summary>
        /// 抗剪切强度，仅钯银要做
        /// </summary>
        public bool bKjqqd;

        /// <summary>
        /// 断面结合强度，纯锡片式产品及锡铅片式产品、钯银产品满足条件时要做
        /// </summary>
        public bool bDmjhqd;

        /// <summary>
        /// 耐焊接热，纯锡片式产品及锡铅片式产品、钯银产品满足条件时要做
        /// </summary>
        public bool bNhjr;

        /// <summary>
        /// 击穿电压，满足条件时要做
        /// </summary>
        public bool bJcdy;

        /// <summary>
        /// 无损检测，纯锡片式产品及锡铅片式产品、钯银产品满足条件时要做
        /// </summary>
        public bool bWsjc;

        /// <summary>
        /// 电性能，必做
        /// </summary>
        public bool bDxn = true;
    }
}
